package com.qf.dao;

import com.qf.pojo.entity.StoreCollect;
import com.qf.pojo.entity.StoreInfo;
import com.qf.pojo.entity.Users;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @ClassName CollectMapper
 * @Description TODO
 * @Author 非乐
 * @Date 2022/9/28 20:30
 * @Version 1.0
 **/
@Mapper
public interface CollectMapper {

//    构建收藏关系
    @Insert("insert into store_collect(user_id,store_id) values(#{userId},#{storeId})")
    int addCollect(StoreCollect collect);

//    排除收藏关系
    @Delete("delete from store_collect where user_id=#{userId} and store_id=#{storeId}")
    int delCollect(StoreCollect collect);

//    查找用户收藏店铺
    @Results(id = "collectMap",value = {
            @Result(column = "id",property = "id"),
            @Result(column = "store_name",property = "storeName"),
            @Result(column = "store_pic",property = "storePic"),
            @Result(column = "store_score",property = "storeScore"),
            @Result(column = "monthly_sale",property = "monthlySale"),
            @Result(column = "monthly_sale",property = "monthlySale"),
            @Result(column = "store_bulletin",property = "storeBulletin"),
            @Result(column = "store_discount",property = "storeDiscount"),
            @Result(column = "store_address",property = "storeAddress"),
    })
    @Select("SELECT s.*\n" +
            "FROM users u,store_info s,store_collect sc\n" +
            "WHERE u.id=sc.user_id AND sc.store_id=s.id\n" +
            "AND u.id=#{id};")
    List<StoreInfo> findStoreById(int id);
}
